package com.ys.filelib.filedialog.adapter;


import android.graphics.Color;

import com.ys.filelib.R;
import com.ys.filelib.filedialog.StorageItem;
import com.ys.filelib.filedialog.adapter.base.BaseViewHolder;
import com.ys.filelib.filedialog.adapter.base.QuickAdapter;
import com.ys.filelib.filedialog.loader.RemoteDiskDao;

public class StorageAdapter extends QuickAdapter<StorageItem> {

    public StorageAdapter() {
        super(R.layout.filelib_item_storage);
    }

    @Override
    protected void convert(BaseViewHolder holder, StorageItem item) {
        holder.setGone(R.id.v_remove, item == null || item.type != RemoteDiskDao.TYPE_FTP);
        holder.setGone(R.id.tv_username, item == null || item.type != RemoteDiskDao.TYPE_FTP);
        if (item == null) {
            holder.setText(R.id.tv_name, R.string.ftp_add);
            holder.setTextColor(R.id.tv_name, 0xFF155ffe);
//            holder.setImageBitmap(R.id.iv_image, null);
            holder.setImageResource(R.id.iv_image, R.drawable.ic_ftp);
            holder.itemView.setBackgroundColor(Color.TRANSPARENT);
            return;
        }
        holder.setText(R.id.tv_name, item.name);
        holder.setText(R.id.tv_username, item.username);
        if (item.check) {
            holder.setImageResource(R.id.iv_image, item.imgRes2);
            holder.itemView.setBackgroundResource(R.drawable.shape_store_bg);
            holder.setTextColorRes(R.id.tv_name, R.color.color_155ffe);
            holder.setTextColorRes(R.id.tv_username, R.color.color_155ffe);
        } else {
            holder.setImageResource(R.id.iv_image, item.imgRes);
            holder.itemView.setBackgroundColor(Color.TRANSPARENT);
            holder.setTextColorRes(R.id.tv_name, R.color.color_333);
            holder.setTextColorRes(R.id.tv_username, R.color.color_333);
        }
    }

    public void clearCheck() {
        for (StorageItem item : getData()) {
            item.check = false;
        }
        notifyDataSetChanged();
    }


}
